# _*_ coding: utf-8 _*_
# @Time : 2020/10/24 16:50
# @Author : liupengfei
# @File : serializers.py
from rest_framework import serializers
from .models import Upload, Option, Area


class UploadSerializer(serializers.ModelSerializer):
    file_url = serializers.SerializerMethodField()

    def get_file_url(self, obj):
        if obj.file_path:
            return obj.get_url()
        return ''

    class Meta:
        model = Upload
        fields = ('id', 'file_url',)


class OptionSerializer(serializers.ModelSerializer):
    class Meta:
        model = Option
        fields = '__all__'


class AreaSerializer(serializers.ModelSerializer):
    class Meta:
        model = Area
        fields = '__all__'
